function popup_gen_name() {
    ar_chars = [
        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
        'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
        'A', 'B', 'C', 'D', 'E', 'F', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
        '_'
    ];
    winName = 'win';
    i_len = ar_chars.length;
    for (i=0; i<6; i++) {
        ind = Math.floor(Math.random()*i_len);
        winName += ar_chars[ind];
    }

    return winName;
}

function popup_image(url, b_width, b_height){

    //url = '/files/'+fname;
    if (b_width == 0) {
        b_width = 200;
    }

    if (b_height == 0) {
        b_height = 150;
    }

    if(b_width > 800){
        w = 800;
    }
    else{
        w = b_width+40;
    }
    if(b_height > 600){
        h = 600;
    }
    else{
        h = b_height+40;
    }
    myWin=window.open(url, '', 'resizable=yes,menubar=no,status=no,scrollbars=yes,width='+w+',height='+h);
}

function popup_win(url, b_width, b_height){

    if(b_width > 800){
        w = 800;
    }
    else{
        w = b_width+40;
    }
    if(b_height > 600){
        h = 600;
    }
    else{
        h = b_height+40;
    }

    winName = popup_gen_name();

    myWin=window.open(url, winName, 'resizable=yes,menubar=no,status=no,scrollbars=yes,width='+w+',height='+h);

    return myWin;
}

function popup_gallery( url ){

    winName = popup_gen_name();

    myWin=window.open(url, winName, 'resizable=yes,menubar=no,status=no,scrollbars=yes,width=500,height=550');

    return myWin;
}